home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / net / SocketInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.3 KB  |  151 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.nio.channels.FileChannel;
  7. import sun.net.ConnectionResetException;
  8.  
  9. class SocketInputStream extends FileInputStream {
  10.    private boolean eof;
  11.    private PlainSocketImpl impl = null;
  12.    private byte[] temp;
  13.    private Socket socket = null;
  14.    private boolean closing = false;
  15.  
  16.    SocketInputStream(PlainSocketImpl var1) throws IOException {
  17.       super(var1.getFileDescriptor());
  18.       this.impl = var1;
  19.       this.socket = var1.getSocket();
  20.    }
  21.  
  22.    public final FileChannel getChannel() {
  23.       return null;
  24.    }
  25.  
  26.    private native int socketRead0(FileDescriptor var1, byte[] var2, int var3, int var4, int var5) throws IOException;
  27.  
  28.    public int read(byte[] var1) throws IOException {
  29.       return this.read(var1, 0, var1.length);
  30.    }
  31.  
  32.    public int read(byte[] var1, int var2, int var3) throws IOException {
  33.       if (this.eof) {
  34.          return -1;
  35.       } else if (this.impl.isConnectionReset()) {
  36.          throw new SocketException("Connection reset");
  37.       } else if (var3 > 0 && var2 >= 0 && var2 + var3 <= var1.length) {
  38.          boolean var5 = false;
  39.          FileDescriptor var6 = this.impl.acquireFD();
  40.  
  41.          try {
  42.             int var4 = this.socketRead0(var6, var1, var2, var3, this.impl.getTimeout());
  43.             if (var4 > 0) {
  44.                int var7 = var4;
  45.                return var7;
  46.             }
  47.          } catch (ConnectionResetException var20) {
  48.             var5 = true;
  49.          } finally {
  50.             this.impl.releaseFD();
  51.          }
  52.  
  53.          if (var5) {
  54.             this.impl.setConnectionResetPending();
  55.             this.impl.acquireFD();
  56.  
  57.             try {
  58.                int var22 = this.socketRead0(var6, var1, var2, var3, this.impl.getTimeout());
  59.                if (var22 > 0) {
  60.                   int var23 = var22;
  61.                   return var23;
  62.                }
  63.             } catch (ConnectionResetException var18) {
  64.             } finally {
  65.                this.impl.releaseFD();
  66.             }
  67.          }
  68.  
  69.          if (this.impl.isClosedOrPending()) {
  70.             throw new SocketException("Socket closed");
  71.          } else {
  72.             if (this.impl.isConnectionResetPending()) {
  73.                this.impl.setConnectionReset();
  74.             }
  75.  
  76.             if (this.impl.isConnectionReset()) {
  77.                throw new SocketException("Connection reset");
  78.             } else {
  79.                this.eof = true;
  80.                return -1;
  81.             }
  82.          }
  83.       } else if (var3 == 0) {
  84.          return 0;
  85.       } else {
  86.          throw new ArrayIndexOutOfBoundsException();
  87.       }
  88.    }
  89.  
  90.    public int read() throws IOException {
  91.       if (this.eof) {
  92.          return -1;
  93.       } else {
  94.          this.temp = new byte[1];
  95.          int var1 = this.read(this.temp, 0, 1);
  96.          return var1 <= 0 ? -1 : this.temp[0] & 255;
  97.       }
  98.    }
  99.  
  100.    public long skip(long var1) throws IOException {
  101.       if (var1 <= 0L) {
  102.          return 0L;
  103.       } else {
  104.          long var3 = var1;
  105.          int var5 = (int)Math.min(1024L, var1);
  106.  
  107.          int var7;
  108.          for(byte[] var6 = new byte[var5]; var3 > 0L; var3 -= (long)var7) {
  109.             var7 = this.read(var6, 0, (int)Math.min((long)var5, var3));
  110.             if (var7 < 0) {
  111.                break;
  112.             }
  113.          }
  114.  
  115.          return var1 - var3;
  116.       }
  117.    }
  118.  
  119.    public int available() throws IOException {
  120.       return this.impl.available();
  121.    }
  122.  
  123.    public void close() throws IOException {
  124.       if (!this.closing) {
  125.          this.closing = true;
  126.          if (this.socket != null) {
  127.             if (!this.socket.isClosed()) {
  128.                this.socket.close();
  129.             }
  130.          } else {
  131.             this.impl.close();
  132.          }
  133.  
  134.          this.closing = false;
  135.       }
  136.    }
  137.  
  138.    void setEOF(boolean var1) {
  139.       this.eof = var1;
  140.    }
  141.  
  142.    protected void finalize() {
  143.    }
  144.  
  145.    private static native void init();
  146.  
  147.    static {
  148.       init();
  149.    }
  150. }
  151.